[Linux] Setting up Django Project on Linux Machine

Let’s find out how to set up a Django project on your Linux machine.

Prerequisites

Ubuntu 18.04 (tested and works on 3/3/20)

sudo apt-get update
sudo apt-get dist-upgrade

if you see something like below, just hit enter

this window might pop up several times, keep hitting enter

1

Install Python

sudo apt-get install python-pip

install pyenv

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

set environment variable for pyenv

vi ~/.bashrc

if you use zsh, open ~/.zshrc

add below in the file

export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
source ~/.bashrc

again, if you use zsh, source ~/.zshrc

install pyenv dependencies

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev

install Python

 pyenv install 3.6.9

install Python libraries

sudo apt-get install python-dev python-setuptools

upgrade pip

pip install --upgrade pip

Create Virtualenv

pyenv virtualenv 3.6.9 <name of your choice>

pyenv virtualenvs : List all Python virtualenvs found in `$PYENV_ROOT/versions/*’

activate virtualenv

pyenv activate <name of virtualenv>

when you activate a virtualenv, you will see something like below in terminal

(name of virtualenv)->....

Clone a Django Project

cd to where you want to put Django Project inside

cd /wherever/you/want

clone Django project

git clone <blabla.git>

Generate SSH key and add key to your Gitlab/Github account:

Getting permission denied (public key) on gitlab

git branch -b <name of your choice>

Install Requirements

pip install -r requirements.txt

For Your Sake

vi ~/.bashrc

add secret key, settings.module, database password to .bashrc/.zshrc so you don’t have to type export SECRET_KEY='blabla' everytime

export SECRET_KEY='<secret-key>'
export DJANGO_SETTINGS_MODULE=<settings-module>
export DATABASE_PASSWORD=<db-password>
source ~/.bashrc

source action with virtualenv activated will deactivate it

activate your virtualenv again

if it says already activated, try pyenv deactivate and then activate it

Test Runserver

cd dir/your/manage.py/lives
python manage.py runserver



Reference

https://stackoverflow.com/questions/40427498/getting-permission-denied-public-key-on-gitlab




ABOUT ME
I write codes and words.
제가 궁금하다면 ABOUT ME 버튼을 눌러보세요!

GitHubLinkedIn